package com.ethan.crm.service.impl;

import com.ethan.crm.domain.Permission;
import com.ethan.crm.mapper.PermissionMapper;
import com.ethan.crm.page.PageResult;
import com.ethan.crm.query.BaseQueryObject;
import com.ethan.crm.service.IPermissionService;
import com.ethan.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionDao;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return permissionDao.deleteByPrimaryKey(id);
    }

    @Override
    public AjaxResult insert(Permission record) {
        return null;
    }

    @Override
    public Permission selectByPrimaryKey(Long id) {
        return permissionDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Permission> selectAll() {
        return permissionDao.selectAll();
    }

    @Override
    public List<String> queryByEid(Long id) {
        return permissionDao.queryByEid(id);
    }

    @Override
    public int updateByPrimaryKey(Permission record) {
        return permissionDao.updateByPrimaryKey(record);
    }

    @Override
    public PageResult queryForPage(BaseQueryObject qo) {
        Long total = permissionDao.queryForPageCount(qo);
        if (total == 0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Permission> permissionList = permissionDao.queryForPage(qo);
        return new PageResult(total.intValue(), permissionList);
    }
}
